home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 631 < prev    next >
Text File  |  1996-08-06  |  1KB  |  27 lines

  1. Newsgroups: comp.std.c
  2. Path: nntp.coast.net!torn!sq!msb
  3. From: msb@sq.com (Mark Brader)
  4. Subject: Re: Restrictions on qsort compare function?
  5. Message-ID: <1996Mar22.204023.10235@sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <4iokop$h4p@lyra.csx.cam.ac.uk> <1996Mar21.113301.2622@sq.com> <4it51b$ng8@usenet.pa.dec.com> <4iukhc$5nr@rdsunx.crd.ge.com>
  8. Date: Fri, 22 Mar 1996 20:40:23 GMT
  9.  
  10. > Alternatively, how about this:
  11. >     return ((signed int) ((unsigned int)a - (unsigned int)b));
  12.  
  13. Assuming that a and b are int, this line cannot produce undefined
  14. behavior, but if a < b, the value returned is implementation-defined
  15. and in particular its sign is not specified by the standard.
  16.  
  17. If the implementation allows this returned value to be non-negative
  18. for some values of a and b, then the function is not a legitimate
  19. comparison function for qsort() because it may not be transitive.
  20. Therefore the code is not strictly conforming.
  21. -- 
  22. Mark Brader, msb@sq.com        "do right; have fun; make money"
  23. SoftQuad Inc., Toronto              -- Ian Darwin on Yuri Rubinsky (1952-96)
  24.  
  25. My text in this article is in the public domain.
  26.